load(
    "@rules_rust//rust:defs.bzl",
    "rust_doc",
    "rust_doc_test",
    "rust_library",
    "rust_test",
    "rust_test_suite",
)

rust_library(
    name = "nativelink-util",
    srcs = [
        "src/action_messages.rs",
        "src/buf_channel.rs",
        "src/channel_body_for_tests.rs",
        "src/chunked_stream.rs",
        "src/common.rs",
        "src/connection_manager.rs",
        "src/digest_hasher.rs",
        "src/evicting_map.rs",
        "src/fastcdc.rs",
        "src/fs.rs",
        "src/fs_util.rs",
        "src/health_utils.rs",
        "src/instant_wrapper.rs",
        "src/known_platform_property_provider.rs",
        "src/lib.rs",
        "src/metrics_utils.rs",
        "src/operation_state_manager.rs",
        "src/origin_event.rs",
        "src/origin_event_publisher.rs",
        "src/platform_properties.rs",
        "src/proto_stream_utils.rs",
        "src/resource_info.rs",
        "src/retry.rs",
        "src/shutdown_guard.rs",
        "src/store_trait.rs",
        "src/task.rs",
        "src/telemetry.rs",
        "src/tls_utils.rs",
        "src/write_counter.rs",
    ],
    proc_macro_deps = [
        "@crates//:async-trait",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "//nativelink-config",
        "//nativelink-error",
        "//nativelink-metric",
        "//nativelink-proto",
        "@crates//:base64",
        "@crates//:bitflags",
        "@crates//:blake3",
        "@crates//:bytes",
        "@crates//:futures",
        "@crates//:hex",
        "@crates//:humantime",
        "@crates//:hyper-1.7.0",
        "@crates//:hyper-util",
        "@crates//:lru",
        "@crates//:mock_instant",
        "@crates//:opentelemetry",
        "@crates//:opentelemetry-appender-tracing",
        "@crates//:opentelemetry-http",
        "@crates//:opentelemetry-otlp",
        "@crates//:opentelemetry-semantic-conventions",
        "@crates//:opentelemetry_sdk",
        "@crates//:parking_lot",
        "@crates//:pin-project",
        "@crates//:pin-project-lite",
        "@crates//:prost",
        "@crates//:prost-types",
        "@crates//:rand",
        "@crates//:rlimit",
        "@crates//:serde",
        "@crates//:sha2",
        "@crates//:tokio",
        "@crates//:tokio-util",
        "@crates//:tonic",
        "@crates//:tower",
        "@crates//:tracing",
        "@crates//:tracing-opentelemetry",
        "@crates//:tracing-subscriber",
        "@crates//:uuid",
        "@crates//:walkdir",
    ],
)

rust_test_suite(
    name = "integration",
    timeout = "short",
    srcs = [
        "tests/action_messages_test.rs",
        "tests/buf_channel_test.rs",
        "tests/channel_body_for_tests_test.rs",
        "tests/common_test.rs",
        "tests/evicting_map_test.rs",
        "tests/fastcdc_test.rs",
        "tests/fs_test.rs",
        "tests/health_utils_test.rs",
        "tests/operation_id_tests.rs",
        "tests/origin_event_test.rs",
        "tests/proto_stream_utils_test.rs",
        "tests/resource_info_test.rs",
        "tests/retry_test.rs",
        "tests/tls_utils_test.rs",
    ],
    compile_data = [
        "tests/data/SekienAkashita.jpg",
        "tests/data/action_message_cachable_060.json",
        "tests/data/action_message_uncachable_060.json",
    ],
    proc_macro_deps = [
        "//nativelink-macro",
        "@crates//:async-trait",
    ],
    deps = [
        ":nativelink-util",
        "//nativelink-config",
        "//nativelink-error",
        "//nativelink-proto",
        "@crates//:bytes",
        "@crates//:futures",
        "@crates//:hex",
        "@crates//:http-body-util",
        "@crates//:hyper-1.7.0",
        "@crates//:mock_instant",
        "@crates//:parking_lot",
        "@crates//:pretty_assertions",
        "@crates//:rand",
        "@crates//:serde_json",
        "@crates//:sha2",
        "@crates//:tempfile",
        "@crates//:tokio",
        "@crates//:tokio-stream",
        "@crates//:tokio-util",
        "@crates//:tonic",
        "@crates//:tracing",
        "@crates//:tracing-test",
        "@crates//:uuid",
    ],
)

rust_test(
    name = "unit_test",
    timeout = "short",
    crate = ":nativelink-util",
    proc_macro_deps = [
        "//nativelink-macro",
    ],
    deps = [
        "@crates//:http-body-util",
        "@crates//:pretty_assertions",
        "@crates//:rand",
        "@crates//:serde_json",
        "@crates//:tempfile",
    ],
)

rust_doc(
    name = "docs",
    crate = ":nativelink-util",
    visibility = ["//visibility:public"],
)

rust_doc_test(
    name = "doc_test",
    timeout = "short",
    crate = ":nativelink-util",
)
